<extend name='Public/index'/>
<block name='content'>
<!-- <form action="?" method='get'> -->
    <!-- <fieldset>
        
            <volist name='vvvo' id='list'>
            <input type="checkbox" name='role_name' value="<{$list.role_name}>"><{$list.role_name}>
            </volist>
            <input type="submit" value='搜索'>
       
    </fieldset> -->
<!-- </form>
 --><table id='Tbl'>
<thead>
	<tr>
		<th><input type="checkbox" onclick="selectAll(this)" value='全选'></th>
		<th>编号</th>
		<th>角色名</th>
		<!-- <th>菜单编号</th> -->
		<th>操作</th>
	</tr>
	</thead>
	<tbody>
	<volist name='roles' id='vo'>
		<tr id="row_<{$vo.role_id}>">
			<td><input type="checkbox" class='select' value='<{$vo.role_id}>' ></td>
			<td><{$vo.role_id}></td>
			 <td><input name="role_name" class="clss"  type="text" value="<{$vo.role_name}>"></td> 
             
			<!-- <td><input name="menu_ids" class="clss"  type="text" value="<{$vo.menu_ids}>"></td>    -->
			<!--<td>
			
             <!-- <div class="switch tiny">
              <input onclick="lock(this)" value="<{$vo.role_id}>" id="lock_<{$vo.role_id}>" type="checkbox"  <{$vo['lock']?'checked':''}>>
                <label for="lock_<{$vo.role_id}>"></label>
                </div>  -->  
			<!-- </td>   -->
			<td>
			<a href="<{:U('editRoles',['role_id'=>$vo['role_id']])}>">角色权限编辑</a>
			<!-- <button style='display:none' onclick='save("<{$vo.role_id}>")' type="button" class="save">保存</button> -->
			</td>
		</tr>
	</volist>
	</tbody>
</table>
<input type="button" class="button tiny" onclick="moreDel()" value='删除(批量)'>
<input type="button" class="button tiny" onclick="unSelect()" value='反选'>
<input type="button" class="button tiny" onclick="add()" value='添加'>
<script>
        function selectAll(obj) {
            $('#Tbl tbody .select').prop('checked',$(obj).prop('checked'));
        }
        function unSelect() {
            $('#Tbl tbody .select').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }
        function moreDel() {
            if(!confirm('确定删除吗?')){
                return;
            }
            var ids = $('#Tbl tbody .select:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<{:U("doDelRole")}>',{ids:ids},function (data) {
                if(data.error ==0)alert(data.msg);
            });
        }
        
        function add(){
            $.get("<{:U('lastId')}>", '',
            function(id){
               var id= parseInt(id)+1;

                var html ="     <tr>"+
    "           <td><input  type=\'checkbox\' class=\'select\' value=\'\' ></td>"+
    "           <td>"+id+"</td>"+
    "           <td><input id=\'row_"+id+"\' name=\'role_name\' class=\'clss\'  type=\'text\' value=\'\'></td>"+
    
    
    
    "           <td>"+
    "           <a  onclick='jump("+id+")'>角色权限编辑</a>"+
    
    "           </td>"+
    "       </tr>";

            $('tbody').append(html);
            
            });
        }
		function jump(id){
			role_name=$('#row_'+id).val();
			window.location.href='<{:U('jump')}>?role_name='+role_name;
		}

        


</script>
</block>